var app = getApp();
Component({

    properties: {
        params: Object,
        showcode : Number,
    },
    data: {
        isshow : false,
        code : '',
        name : '',
        tel : '',
        pcard : '',
        isauthed : false,
    },
    options : {
        addGlobalClass : true,
    },
    methods: {
        navigateto : function( e ){
            app.com.navigateto( e );
        },
        showfn(){
            this.setData({
                isshow : !this.data.isshow
            })
        },
        bindCode(){
            this.setData({
                isshow : true
            })
        },
        confirm(){
            var self = this;
            if(this.data.params.needauth == 1 && !this.data.isauthed){
                this.selectComponent('#loginauth').hideauth();
                return false;
            }

            var postdata = {
                op:'passbycode',
                code:self.data.code,
                name:self.data.name,
                tel : self.data.tel,
                pcard : self.data.pcard,
                v : 1,
            };

            if( !app.com.verify('mobile', postdata.tel ) ) {
                app.com.toast('请填写正确的电话号码');
                return false;
            }

            app.com.http('ucard','POST',postdata,0,true,'','',function(res){
                if (!res.data.errno) {
                    app.com.toast('已开通','success',function(){
                        self.setData({
                            isshow : false,
                        });
                        self.triggerEvent('success',{time:res.data.data.cardend});
                    });
                }else{
                    app.com.alert(res.data.message);
                }
            });
        },
        authed(){
            var self = this;
            self.setData({
                isauthed : true,
            })
            self.confirm();
        },
        changeinput(e){
            var key = e.currentTarget.dataset.name;
            this.setData({
                [key] : e.detail.value
            })
        },
    }

})